<%@ page import="com.sx.dao.PlayerfoDAO" %>
<%@ page import="com.sx.domain.Player" %><%--
  Created by IntelliJ IDEA.
  User: Asus
  Date: 2021/6/28
  Time: 9:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
  Player player = null;
  try {
    player = PlayerfoDAO.findByKey(" id = " + request.getParameter("id") + " ").get(0);
  } catch (Exception e) {
    e.printStackTrace();
  }

%>
<div class="layuimini-main">

  <div class="layui-form layuimini-form">
    <form id="play_form">
      <div class="layui-form-item">
        <label class="layui-form-label required">游戏名称</label>
        <div class="layui-input-block">
          <input type="text" id="username" name="username" lay-verify="required" lay-reqtext="游戏名称不能为空" placeholder="请输入游戏名称" value=<%=player.getName()%> class="layui-input">
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label">年龄</label>
        <div class="layui-input-block">
          <input type="text" id="age" name="age" placeholder="请输入年龄" value=<%=player.getAge()%> class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label required">电话号码</label>
        <div class="layui-input-block">
          <input type="text" id="tel" name="phone" lay-verify="required" lay-reqtext="电话号码不能为空" placeholder="请输入电话号码" class="layui-input"  value=<%=player.getTel()%> >
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label">球队名称</label>
        <div class="layui-input-block">
          <input type="text" id="team" name="team" lay-verify="required" placeholder="请输入球队名称" lay-reqtext="球队名称不能为空" placeholder="请输入球队名称" value=<%=player.getTeam()%> class="layui-input">
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label required">球队编号</label>
        <div class="layui-input-block">
          <input type="number" id="team_id" name="team_id" lay-verify="required"   lay-reqtext="球队编号不能为空" placeholder="请输入球队编号" value=<%=player.getTeam_id()%> class="layui-input">
        </div>
      </div>

      <div class="layui-form-item">
        <div class="layui-input-block">
          <button type="button" class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认</button>
        </div>
      </div>
    </form>

  </div>
</div>
<script>
  layui.use(['form', 'table','layer'], function () {
    var form = layui.form,
      layer = layui.layer,
      table = layui.table,
      $ = layui.$;

    /**
     * 初始化表单，要加上，不然刷新部分组件可能会不加载
     */
    form.render();

    // 当前弹出层，防止ID被覆盖
    var parentIndex = layer.index;

    //监听提交
    form.on('submit(saveBtn)', function (data) {
      var username = $('#username').val();
      var age = $('#age').val();
      var tel = $('#tel').val();
      var team = $('#team').val();
      var team_id = $('#team_id').val();
      $.ajax({
        type: "POST",
        dataType: "text",
        url: "http://localhost:8081/PlayerManagement_war_exploded/updatePlayerServlet",//url
        data: {id:<%=player.getId()%>,name:username,age:age,tel:tel,team:team,team_id:team_id },//这个是form表单中的id，jQuery的serialize()方法通过序列化表单值
        success: function (data) {
          if(data=="ok"){
            layer.msg("修改成功");
            // 关闭弹出层
            layer.close(index);
            layer.close(parentIndex);
          }else{
            layer.msg("修改失败");
          }
        }
      });


      return false;
    });

  });
</script>

